//
//  HotViewcontroller.m
//  YSBEmployee
//
//  Created by developer on 2021/11/30.
//  Copyright © 2021 ysb. All rights reserved.
//
#import "AppDelegate.h"

#import "YSBWebViewController.h"

#import "YSBAnnouncementScrollView.h"

#import "YSBHomeController.h"

#import "YSBChatRoomWebSocketManager.h"

#import "YSBMessageListHomeViewController.h"



@implementation AppDelegate


- (void)faceStart {
    [self.locationManager startUpdatingLocation];
    
}


- (void)faceStop {
    [self.locationManager stopUpdatingLocation];
    
}


@end



@implementation YSBWebViewController

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];

    
    
}


@end



@implementation YSBAnnouncementScrollView


- (void)backGoBtnWithModel:(YSBAnnouncementModel *)model {
    
    if (self.clickBottomBtnBlock) {
        self.clickBottomBtnBlock(model);
    }
    NKAlertView *alertView = (NKAlertView *)self.superview;
    [alertView viewHidden];
    
    NSUserDefaults *localSave = [NSUserDefaults standardUserDefaults];
    [localSave setObject:[NSNumber numberWithBool:NO] forKey:@"closeHomeActivityKey"];
    [localSave synchronize];
    
}


- (void)bottomTouchTap:(UITapGestureRecognizer *)sender{
    
    self.closeImgView.hidden = YES;
    self.btnInfoLabel.hidden = YES;

    if (self.clickClosedBtnBlock) {
        self.clickClosedBtnBlock();
    }
    [self.main removeFromSuperview];
    NKAlertView *alertView = (NKAlertView *)self.superview;
    [alertView hide];
    
    NSUserDefaults *localSave = [NSUserDefaults standardUserDefaults];
    [localSave setObject:[NSNumber numberWithBool:YES] forKey:@"closeHomeActivityKey"];
    [localSave synchronize];
    
}


@end



@implementation YSBHomeController


- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    CGFloat showTime = 2.5f;
    
    NSUserDefaults *localSave = [NSUserDefaults standardUserDefaults];
    NSNumber *isCloseHomeActivityNum = [localSave objectForKey:@"closeHomeActivityKey"];
    BOOL isCloseHomeActivity = isCloseHomeActivityNum.boolValue;
    if (isCloseHomeActivity == 0) {
        showTime = 0;
    }

    [self performSelector:@selector(delayShowAdMethod) withObject:nil afterDelay:showTime];
    
}

- (void)delayShowAdMethod {
    if ([YSBMSAlertManager shareManager]) {
        [[YSBMSAlertManager shareManager] showAlerts];
    }
}


@end



@implementation YSBChatRoomWebSocketManager


- (void)webSocketDidOpen:(SRWebSocket *)webSocket{
    NSLog(@"已经连接,开启心跳");

    NSDictionary *dict = @{
        @"action":@(1),
    };

    [self sendDataToServer:dict];
    
    self.isConnect = YES;
    self.socketStatus = 1;
    [self initHeartBeat];//开始心跳
    
    [self performSelector:@selector(delayShowTabBarItemBadgeValueMethod) withObject:nil afterDelay:1];
    
}

- (void)delayShowTabBarItemBadgeValueMethod {
    NSUserDefaults *localSave = [NSUserDefaults standardUserDefaults];
    //读取在数客服消息条数
    NSString *unread_msg_num = [localSave objectForKey:@"customerMsgNumKey"];
    unread_msg_num = [YSBCommonTool isBlankString:unread_msg_num] ? @"0" : unread_msg_num;
        
    UITabBarController *root = [YSBCommonTool getCurrentVC].tabBarController; // 当前的viewController
    UITabBarItem *tabBarItem = [UITabBarItem new];
    
    if (unread_msg_num.integerValue > 0) {
        
        if (root.tabBar.items.count > 2) {
            tabBarItem = root.tabBar.items[2];// 拿到需要设置角标的tabarItem
            [tabBarItem setBadgeValue:@"客服+"];
        }
        
    }else{
        [tabBarItem setBadgeValue:nil];// 隐藏角标
    }
    
}



@end



@implementation YSBMessageListHomeViewController


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.tabBarItem.badgeValue = nil;

    [self requestData];
    
}



@end
